package com.yonyou.pmclouds.team.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.mapper.ProjectMapper;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import com.yonyou.pmclouds.team.entity.TeamEnterpriseViewVO;
import com.yonyou.pmclouds.team.rmiitf.TeamEnterOpenQuery;
import com.yonyou.pmclouds.team.rmiitf.TeamEnterpriseQuery;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
@Service(version = ApplicationConsts.APPLICATION_VERSION, interfaceClass = TeamEnterOpenQuery.class)
public class TeamEnterOpenQueryImpl implements TeamEnterOpenQuery {

    @Autowired
    private ProjectSimpleQuery projectQuery;
    @Autowired
    private TeamEnterpriseQuery teamEnterpriseQuery;
    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public TeamEnterpriseViewVO[] getTeamInfoByProject(String pkTenant, String pkProSrc) throws BusinessException {

        ProjectVO[] projectVOs = projectMapper.queryVOBySrcIds(pkTenant,new String[]{pkProSrc});
        if(ArrayUtils.isEmpty(projectVOs))
            return new TeamEnterpriseViewVO[0];

        TeamEnterpriseViewVO[] teamEntViewVOs = teamEnterpriseQuery.queryEnterpriseViewVOsByProject(projectVOs[0].getPkProject());

        if(teamEntViewVOs == null)
            return new TeamEnterpriseViewVO[0];

        return teamEntViewVOs;
    }
}
